home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
vol_100
/
108_01
/
cc0t.c
< prev
next >
Wrap
Text File
|
1985-11-13
|
2KB
|
79 lines
/*
CC0T.C -- TRS-80 C PREPROCESSOR
WRITTEN BY LEOR ZOLMAN
THIS PROGRAM TAKES, AS INPUT, A C SOURCE FILE WRITTEN
USING THE SPECIAL "POUND SIGN" ENCODING FOR CHARACTERS
WHICH ARE UNPRINTABLE (AND UNENTERABLE) ON THE EARLY
MODEL TRS-80 COMPUTERS. WHEREVER CC0T FINDS A SEQUENCE
#X
IN THE INPUT FILE, WHERE "X" IS ONE OF THE SPECIAL
CHARACTERS AS OUTLINED IN THE SOURCE FOR CONVERT.C,
THEN THE TWO-CHARACTER SEQUENCE IS CONVERTED TO A
SINGLE CHARACTER AS REQUIRED BY THE BDS C COMPILER.
THE RESULTANT FILE MAY THEN BE COMPILED WITH CC1, CC2,
ETC.
*/
#DEFINE POUND 0X23
#DEFINE LEFTBRACK 0X5B
#DEFINE BACKSLASH 0X5C
#DEFINE RIGHTBRACK 0X5D
#DEFINE CIRCUM 0X7E
#DEFINE VERTIBAR 0X7C
#DEFINE UNDERSCORE 0X5F
#DEFINE UPARROW 0X5E
CHAR IBUF[134], OBUF[134];
MAIN(ARGC,ARGV)
INT ARGC;
CHAR *ARGV[];
BEGIN
INT FD1, FD2;
CHAR C;
IF (ARGC != 3) BEGIN
PRINTF("USAGE: CC0T OLD NEW <CR>\N");
EXIT();
END
FD1 = FOPEN(ARGV[1],IBUF);
IF (FD1 == -1) BEGIN
PRINTF("CANNOT OPEN INPUT FILE.\N");
EXIT();
END
FD2 = FCREAT(ARGV[2],OBUF);
IF (FD2 == -1) BEGIN
PRINTF("CANNOT OPEN OUTPUT FILE.\N");
EXIT();
END
WHILE ((( C = GETC(IBUF)) != 0X1A) && C != 255)
BEGIN
IF (C != POUND) PUTC(C,OBUF);
ELSE SWITCH(C = GETC(IBUF))
BEGIN
CASE 'B': PUTC(BACKSLASH,OBUF);
BREAK;
CASE 'L': PUTC(LEFTBRACK,OBUF);
BREAK;
CASE 'R': PUTC(RIGHTBRACK,OBUF);
BREAK;
CASE 'C': PUTC(CIRCUM,OBUF);
BREAK;
CASE 'V': PUTC(VERTIBAR,OBUF);
BREAK;
CASE 'U': PUTC(UNDERSCORE,OBUF);
BREAK;
CASE 'H': PUTC(UPARROW,OBUF);
BREAK;
DEFAULT: PUTC(POUND,OBUF);
PUTC(C,OBUF);
END
END
IF (C == 255) C = 0X1A;
PUTC(C,OBUF);
FFLUSH(OBUF);
END